]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tools/toolbox: Add build convenience script
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 1 Sep 2023 01:55:43 +0000 (03:55 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 1 Dec 2023 15:58:21 +0000 (15:58 +0000)
We don't require any build steps other than the standard meson
commands, but entering a toolbox and running 2-3 meson commands
still adds some friction.

Add a small convencience script that
 - finds the toplevel source directory (similar to `jhbuild make`)
 - enters the speficied toolbox (or the configured default)
 - automatically picks a build directory based on the toolbox name
 - builds and installs the project to /usr (inside the toolbox)

It also allows specifying meson -D options to change the build
configuration, and to optionally run `meson dist`.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2935>

tools/toolbox/meson-build.sh [new file with mode: 0755]

diff --git a/tools/toolbox/meson-build.sh b/tools/toolbox/meson-build.sh
new file mode 100755 (executable)
index 0000000..5b41305
--- /dev/null
@@ -0,0 +1,99 @@
+#!/bin/bash
+
+DEFAULT_TOOLBOX=gnome-shell-devel
+CONFIG_FILE=${XDG_CONFIG_HOME:-$HOME/.config}/gnome-shell-toolbox-tools.conf
+
+usage() {
+  cat <<-EOF
+       Usage: $(basename $0) [OPTION…]
+
+       Build and install a meson project in a toolbox
+
+       Options:
+         -t, --toolbox=TOOLBOX   Use TOOLBOX instead of the default "$DEFAULT_TOOLBOX"
+
+         -Dkey=val               Option to pass to meson setup
+         --dist                  Run meson dist
+
+         -h, --help              Display this help
+
+       EOF
+}
+
+die() {
+  echo "$@" >&2
+  exit 1
+}
+
+find_toplevel() {
+  while true; do
+    grep -qs '\<project\>' meson.build && break
+    [[ $(pwd) -ef / ]] && die "Error: No meson toplevel found"
+    cd ..
+  done
+}
+
+needs_reconfigure() {
+  [[ ${#MESON_OPTIONS[*]} > 0 ]] &&
+  [[ -d $BUILD_DIR ]]
+}
+
+# load defaults
+. $CONFIG_FILE
+TOOLBOX=$DEFAULT_TOOLBOX
+
+TEMP=$(getopt \
+  --name $(basename $0) \
+  --options 't:D:h' \
+  --longoptions 'toolbox:' \
+  --longoptions 'dist' \
+  --longoptions 'help' \
+  -- "$@")
+
+eval set -- "$TEMP"
+unset TEMP
+
+MESON_OPTIONS=()
+
+while true; do
+  case $1 in
+    -t|--toolbox)
+      TOOLBOX=$2
+      shift 2
+    ;;
+
+    --dist)
+      RUN_DIST=1
+      shift
+    ;;
+
+    -D)
+      MESON_OPTIONS+=(-D$2)
+      shift 2
+    ;;
+
+    -h|--help)
+      usage
+      exit 0
+    ;;
+
+    --)
+      shift
+      break
+    ;;
+  esac
+done
+
+find_toplevel
+
+BUILD_DIR=build-$TOOLBOX
+[[ $RUN_DIST ]] && DIST="meson dist -C $BUILD_DIR" || DIST=:
+
+needs_reconfigure && RECONFIGURE=--reconfigure
+
+toolbox run --container $TOOLBOX sh -c "
+  meson setup --prefix=/usr $RECONFIGURE ${MESON_OPTIONS[*]} $BUILD_DIR &&
+  meson compile -C $BUILD_DIR &&
+  sudo meson install -C $BUILD_DIR &&
+  $DIST
+"